//
//  TreeTableViewSection.m
//  X-Touch2
//
//  Created by shengchao yang on 12-3-28.
//  Copyright (c) 2012年 foxhis. All rights reserved.
//

#import "TreeTableViewSection.h"
#import "FileManager.h"
#import "UIBadgeView.h"
#import "DataBaseAccess.h"

@interface TreeTableViewSection(Private)
- (void) add1fingerTap;	
@end

@implementation TreeTableViewSection
@synthesize delegate;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        [self add1fingerTap];
    }
    return self;
}
-(void) setData:(NSString *)data menuCode:(NSString *)pmCode{
    UILabel *lblPmDescript = (UILabel *)[self.view viewWithTag:TagOfUILabel];
    lblPmDescript.text = data;
    
    float pluMenuCount = [DataBaseAccess getPluMenuCount:pmCode];
    if (pluMenuCount > 0) {
        //设置标签数据
        UIBadgeView *badgeView=[[UIBadgeView alloc] initWithFrame:CGRectMake(0, 0, 30, 20)];
        badgeView.badgeString = [NSString stringWithFormat:@"%d",(int)pluMenuCount];
        badgeView.badgeColor = [UIColor redColor];
        [self.view addSubview:badgeView];
        [badgeView release];
    }
}
-(void) setSelectedSection:(BOOL)selected{
    UIImageView *imgArrow = (UIImageView *)[self.view viewWithTag:TagOfUIImageView];
    if (selected) {
        imgArrow.image = [FileManager getImage:@"arrow_down.png" type:3 withRect:imgArrow.frame]; 
    }else {
        imgArrow.image = [FileManager getImage:@"arrow_up.png" type:3 withRect:imgArrow.frame]; 
    }
}
#pragma mark - GestureRecognizer
- (void) add1fingerTap{
	UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapFrom:)];
    recognizer.numberOfTouchesRequired = 1;//多少跟手指
    recognizer.numberOfTapsRequired = 1;//点击几次
    recognizer.delegate = self;
	[self.view addGestureRecognizer:recognizer];
	[recognizer release];	
}
- (void)handleTapFrom:(UITapGestureRecognizer *)recognizer {
    if (self.delegate) {
        [self.delegate tableViewSection:self.view didTappedAtSection:self.view.tag-TagOfUITableViewSection];
    }else{
        MyNSLog(@"没有实现TreeTableViewDelegate!!!");
    }
}

#pragma mark - View lifecycle
- (void)viewDidLoad{
    [super viewDidLoad];
}
- (void)viewDidUnload{
    [super viewDidUnload];
}
- (void)didReceiveMemoryWarning{
    [super didReceiveMemoryWarning];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
-(void)dealloc{
    MyNSLog(@"TreeTableViewSection dealloc index=%d",self.view.tag - TagOfUITableViewSection);
    [super dealloc];
}
@end
